package com.oren.system.service.imp;

import com.oren.base.pojo.Page;
import com.oren.system.mapper.UserMapper;
import com.oren.system.pojo.User;
import com.oren.system.service.UserService;
import com.oren.util.PageUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author: oren
 * @Description:
 * @Date: Create on 2017/11/7 0007 09:48
 */
@Service
@Transactional
public class userServiceImp   implements UserService {

	@Autowired
	private UserMapper userMapper;


	public User getUserByUserName(String username) throws Exception {
		return userMapper.getUserByUsername(username);
	}

	public Page<User> pageList(User user,int pageNum,int pageSize) throws Exception {
		List<User> list=userMapper.pageList(user,PageUtil.getBound(pageNum,pageSize));
		int total=userMapper.total(user);
		return PageUtil.getPageList(list,total);
	}

	public boolean reg(User user) throws Exception {
		int i=userMapper.insertUser(user);
		if(i==1){
			return true;
		}
		return false;
	}

	@Override
	public User login(String username, String password) throws Exception {
		Map map=new HashMap();
		map.put("username",username);
		map.put("password",password);
		return userMapper.findUserByUsernamePassword(map);
	}

	@Override
	public int deleteUserByIds(String[] ids) throws Exception {
		return userMapper.deleteById(ids);
	}

}
